import java.util.List;
import java.util.Scanner;

public class Test {
    static class Node{
        int val;
        Node next;
        public Node(int v){
            this.val = v;
        }
    }
    public static Node createCircle(int n){
        Node pHead = new Node(1);
        Node pTail = pHead;
        for(int i = 2;i <= n;i++){
            pTail.next = new Node(i);
            pTail = pTail.next;
        }
        pTail.next = pHead;
        return pTail;
    }
    public static int ysf (int n, int m,int[] arr) {
        // write code here
        Node prev = createCircle(n);
        Node cur = prev.next;
        int count = 1;
        int countArr = 0;
        //使用count来计数
        while(cur.next != cur){
            if(count == m){
                // 删除的操作
                arr[countArr++] = cur.val;
                prev.next = cur.next;
                cur = cur.next;
                count = 1;

            }
            prev = cur;
            cur = cur.next;
            count++;
        }
        arr[countArr] =cur.val;
        return cur.val;
    }


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入人数n:");
        int n = sc.nextInt();
        System.out.println("请输入报数m:");
        int m = sc.nextInt();
        System.out.println("请输入第k个出列的人:");
        int k = sc.nextInt();
        int[] delete = new int[n];
        int ret = ysf(n,m,delete);
        // System.out.println("最后一个出列的人:" + ret);
        for (int i = 0; i < n; i++) {
            System.out.print(delete[i] + " ");
        }
        System.out.println();
        System.out.println("第"+ k + "个出列的人:" +delete[k-1]);
    }
}
